<?
$uploadfolder    = $_SESSION["UPLOADFOLDER"];
?>

<script type="text/javascript" >
	$(function(){
		var btnUpload=$('#upload');
		var status=$('#status');
		new AjaxUpload(btnUpload, {
			action: 'Admin/ajax-file-upload/upload-file.php',
			name: 'uploadfile',
			onSubmit: function(file, ext){
				 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
                    // extension is not allowed 
					status.text('Only JPG, PNG or GIF files are allowed');
					return false;
				}
				status.text('Uploading...');
			},
			onComplete: function(file, response){
				//On completion clear the status
				status.text('');
				//Add uploaded file to list
				if(response==="success"){
					$('<div></div>').appendTo('#files').html('<img src="<?=$uploadfolder?>/'+file+'" alt="" /><div>'+file+'</div><div><input type=\'text\' value=\'<?=$uploadfolder?>/'+file+'\'/></div>').addClass('item success');
				} else{
					$('<div></div>').appendTo('#files').text(file+response).addClass('item error');
				}
			}
		});
		
	});
</script>
<table>
    <tr>
        <td>
            <div style="width: 240px;background: #eee;float: left;overflow: auto;max-height: 500px;">
            <?
            
            
            $folders = scandir("../Product");
            echo "
                    <div class='folder' onclick=\"changeuploadfolder('Product');\">
                        <img width=20 src='./images/icon/folder.png' />
                        <span>..</span>
                
                    </div>
            ";
            foreach($folders as $folder){
                if($folder!="." && $folder!=".." && is_dir("../Product/".$folder))
                echo "
                    <div class='folder' onclick=\"changeuploadfolder('Product/$folder');\">
                        <img width=20 src='./images/icon/folder.png' />
                        <span>$folder</span>
                
                    </div>
                    ";
            }
            ?>
            </div>
        </td>
        <td>
            <div id="mainbody" style="float: left;width: 100%;" >
        		<!--<h3>&raquo; AJAX File Upload Form Using jQuery</h3>-->
        		<!-- Upload Button, use any id you wish-->
        		<div id="upload" ><span>Upload File<span></div><span id="status" ></span>
        		<hr />
                
            </div>
        
            <span id="files">
    		    <?
                define('PATH', "../Product"); // Khai báo đường đẫn đến thư mục
                $files = array();
                $dir = opendir(PATH);
                while ($f = readdir($dir)){
                if(eregi("\.jpg|\.gif|\.png",$f))
                array_push($files,$f);
                }
                closedir($dir);
                $data = array();
                if(!empty($files)){
                foreach ($files as $k => $v){
                echo "
                    <div class='item success'>
                        
                        <div>$v</div>
                        <div><input type='text' value='Product/$v'/></div>
                    </div>
                    ";
                }
                }else echo "No image.";
                ?>
            
            </span>
        </td>
    </tr>
</table>

